# Your Solution object will be instantiated and called as such:
# obj = Solution(nums)
# param_1 = obj.pick(target)
import random
from collections import defaultdict


class Solution:
    def __init__(self, nums: list):
        self.mid_dic = defaultdict(list)
        for index, num in enumerate(nums):
            self.mid_dic[num].append(index)

    def pick(self, target: int) -> int:
        return self.mid_dic[target][random.randint(0, len(self.mid_dic[target]) - 1)]
